package web.suzy.oj.service.file.impl;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import web.suzy.oj.common.exception.StatusFailException;
import web.suzy.oj.common.exception.StatusSystemErrorException;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.common.result.ResultStatus;
import web.suzy.oj.manager.file.ImageManager;
import web.suzy.oj.service.file.ImageService;

import javax.annotation.Resource;
import java.util.Map;

/**
 * YangSuzy 软件工作室
 * 类名: ImageServiceImpl
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/30 11:30
 */
@Service
public class ImageServiceImpl implements ImageService {
    @Resource
    private ImageManager imageManager;

    /**
     * 方法名: uploadAvatar
     * 描述: 上传头像
     *
     * @param image 头像图片
     * @return web.suzy.oj.common.result.ResultBean<java.util.Map < java.lang.Object, java.lang.Object>>
     * @date 2022/11/30 11:30
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Map<Object, Object>> uploadAvatar(MultipartFile image) {
        try {
            return ResultBean.successResponse(imageManager.uploadAvatar(image));
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        } catch (StatusSystemErrorException e) {
            return ResultBean.errorResponse(e.getMessage(), ResultStatus.SYSTEM_ERROR);
        }
    }

    /**
     * 方法名: uploadCarouselImg
     * 描述: 上传主页轮播图
     *
     * @param image 图片文件
     * @return web.suzy.oj.common.result.ResultBean<java.util.Map < java.lang.Object, java.lang.Object>>
     * @date 2022/11/30 11:49
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Map<Object, Object>> uploadCarouselImg(MultipartFile image) {
        try {
            return ResultBean.successResponse(imageManager.uploadCarouselImg(image));
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        } catch (StatusSystemErrorException e) {
            return ResultBean.errorResponse(e.getMessage(), ResultStatus.SYSTEM_ERROR);
        }
    }
}
